/**
 * Copyright (C), 2020-2020, 软件公司
 * FileName: SuspendProcess.java
 * Author:   cakin
 * Date:     2020/4/25
 * Description: 中断和激活流程
 */
package com.syc.activiti.chapter9;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.runtime.ProcessInstance;

/**
 * @className: SuspendProcess
 * @description: 中断和激活流程
 * @date: 2020/4/25
 * @author: cakin
 */
@Slf4j
public class SuspendProcess {

    public static void main( String[] args ) {
        // 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
        // 得到流程存储服务实例
        RepositoryService repositoryService = engine.getRepositoryService();
        // 得到运行时服务组件
        RuntimeService runtimeService = engine.getRuntimeService();
        // 部署流程描述文件
        repositoryService.createDeployment()
                .addClasspathResource("bpmn/chapter9/SuspendProcess.bpmn").deploy();
        // 开始流流程
        ProcessInstance pi = runtimeService
                .startProcessInstanceByKey("testProcess");
        // 中断流程
        runtimeService.suspendProcessInstanceById(pi.getId());
        ExecutionEntity exe = (ExecutionEntity) runtimeService
                .createExecutionQuery().parentId(pi.getId())
                .singleResult();
        log.info("中断后执行流状态：" + exe.isSuspended());
        // 激活流程
        runtimeService.activateProcessInstanceById(pi.getId());
        exe = (ExecutionEntity) runtimeService.createExecutionQuery()
                .parentId(pi.getId())
                .singleResult();
        log.info("激活后执行流状态：" + exe.isSuspended());
    }

}
